package com.ktjy.controller;


import com.ktjy.entity.SysRight;
import com.ktjy.entity.SysUser;
import com.ktjy.service.ISysRightService;
import com.ktjy.utils.UserUtils;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lqm
 * @since 2025-02-25
 */
@RestController
@RequestMapping("/sysRight")
public class SysRightController {


    @Autowired
    ISysRightService service;

    @Autowired
    UserUtils userUtils;

    /**
     * 查询当前用户可访问的资源
     *
     * @return
     */
    @RequestMapping("/listByUser")
    @PreAuthorize("hasRole('admin')")
    @Secured("ROLE_admin")
    public List<SysRight> getListByRole(HttpServletRequest request) {

        long roleId = userUtils.getRoleByRequest(request);

        List<SysRight> list = service.getListByRoleId(roleId);
        return list;

    }


}
